package cn.signalpha.modules.social.service;

import cn.signalpha.core.mp.service.impl.ExtendServiceImpl;
import cn.signalpha.modules.social.entity.Blacklist;
import cn.signalpha.modules.social.mapper.BlacklistMapper;
import cn.signalpha.modules.social.vo.BlacklistVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class BlacklistService extends ExtendServiceImpl<BlacklistMapper, Blacklist> {

	/**
	 * 自定义分页
	 */
    public IPage<BlacklistVO> selectBlacklistPage(IPage<BlacklistVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectBlacklistPage(page, params));
    }

	/**
	 * 获取我的黑名单用户id
	 */
	public List<Long> getUserIds(Long userId) {
		return list(Wrappers.<Blacklist>lambdaQuery().eq(Blacklist::getUserId, userId)).stream().map(Blacklist::getTargetId).collect(Collectors.toList());
	}

	/**
	 * 查询
	 */
    public Blacklist getByUserIdAndTargetId(Long userId, Long targetId) {
		return baseMapper.selectOne(Wrappers.<Blacklist>lambdaQuery().eq(Blacklist::getUserId, userId).eq(Blacklist::getTargetId, targetId));
    }
}

